<template>
	<div class='main'>
		<div class="cover_c">
			<div class="cover">
				<img src="https://xxx.oss.com/dxdh/%E8%92%99%E7%89%88%E7%BB%84%201.png" alt=""
					style="width:100%;height:100%">
			</div>
		</div>
		<div class="content" v-if="display">
			<div class="title">
				<div>基本信息</div>
				<div class="word">{{form1.province}}</div>
			</div>

			<!--     <div class="middle">
                <div class="blue"></div>
                <div class="subtitle">一、我的“基本信息”</div>
            </div> -->
			<!-- <div class="explain">填写相关信息后，点击“开始自主填报”按钮，考生就可以在了解自己“往年当量”的基础上，开始志愿的智能化自主填报了。</div>
            <div class="explain">新高考的地区批次，科类选择新高考;传统高考的地区批次，科类请选择对应的批次及科目</div>
            <div class="explain">新高考分物理类和历史类的，科类请选择相对应的科类;批次选择新高考</div> -->
			<div class="form">
				<div class="left">
					<el-form ref="form" :model="form" label-width="150px" style="width:400px;" size="medium"
						id="selectform">
						<!-- <el-form-item label="所在省份: ">
                            <el-select v-model="form.province" placeholder="请选择您所在省份" style="width:100%">
                            <el-option :label="item.provinceName" :value="item.id" v-for="(item,index) in allProvince" :key="index"></el-option>
                            </el-select>
                        </el-form-item> -->
						<el-form-item label="选择批次: " style="margin-top:56px;">
							<el-select v-model="form.batches" placeholder="请选择您的高考批次" style="width:100%">
								<el-option label="本科一批" value=0></el-option>
								<el-option label="本科二批" value=1></el-option>
								<el-option label="新高考" value=2></el-option>
							</el-select>
						</el-form-item>
						<el-form-item label="参考年份: " style="margin-top:35px">
							<el-select v-model="form.region" placeholder="请选择您的参考年份" style="width:100%">
								<el-option :label="ReferenceYear" :value="ReferenceYear"></el-option>
								<el-option :label="ReferenceYear-1" :value="ReferenceYear-1"></el-option>
								<el-option :label="ReferenceYear-2" :value="ReferenceYear-2"></el-option>
								<!-- <el-option label="区域二" value="beijing"></el-option> -->
							</el-select>
						</el-form-item>
					</el-form>
					<div class="explain2">建议选择距当年最近那一年份作参考</div>
				</div>
				<div class="right">
					<el-form ref="form" :model="form" label-width="150px" style="width:500px;float:right" size="medium"
						id="selectform">
						<!-- <el-form-item label="参考年份: ">
                            <el-select v-model="form.region" placeholder="请选择您的高考年份" style="width:100%">
                            <el-option label="2020" value=2020></el-option>
                            <el-option label="2019" value=2019></el-option>
                            </el-select>
                        </el-form-item> -->
						<el-form-item label="选择科类: " style="margin-top:56px">
							<el-select v-model="form.subject" placeholder="请选择您所属科类" style="width:100%">
								<el-option label="文科/历史类" value=0></el-option>
								<el-option label="理科/物理类" value=1></el-option>
								<el-option label="新高考" value=2></el-option>
							</el-select>
						</el-form-item>
						<el-form-item label="高考分数: " style="margin-top:35px 	">
							<el-input v-model="form.score" :disabled="cardstatus" placeholder="请填写您的分数" class="input">
							</el-input>
						</el-form-item>
					</el-form>
					<div class="explain1">
						<h2 style="color:red;">填报警示:</h2>
						<div class="suoji">1.每年<span style="color:red">6月22日00:00时---当年8月31日24:00时期间：注册账户只能凭借卡号和密码方可登录系统，输入一个真实的高考分数，</span>
						进行志愿方案的自主设计；同时，该卡号和密码一经使用将被锁定，不能再输入其他分数进行志愿方案的自主设计，但可以重复登录查看、修改志愿方案。
						</div>
						<div class="suoji">2.每年<span style="color:red">9月01日00:00时---次年6月21日24:00时期间：</span>
						新、老注册账户凭注册账号、密码可登录系统输入<span style="color:red">无限个</span>成绩，进行<span style="color:red">无限次</span>模拟填报。</div>
						<!-- <div class="suoji">3.本平台<span style="color:red">当前</span>仅支持除新疆、西藏、云南、吉林、内蒙省（区）外的其它26个省（市、区）的<span style="color:red">普通本科</span>志愿填报。 -->
						<div class="suoji">3.本平台<span	style="color:red;">当前</span>可为除新疆、西藏、云南、吉林、内蒙省（区）外的其它26个省（市、区）的<span
						style="color:red;">普通本科</span>高考志愿填报提供参考服务。
						</div>
					</div>
				</div>
			</div>
			<div class="leftside">
				<div class="cndns-right-btn">
					<el-link :underline="false">
						<i class="el-icon-s-home"></i>
						<div class="text">首页</div>
					</el-link>
				</div>
				<div class="cndns-right-btn">
					<!-- <el-tooltip class="item" effect="light" content="进入往年当量" hide-after="5000" placement="left-start"> -->
					<el-link @click="jumpTo()" :underline="false">
						<i class="iconfont icon-xiayiye"></i>
						<div class="text">往年当量</div>
					</el-link>
					<!-- </el-tooltip> -->
				</div>
			</div>
			<div class="select">
				<!-- <el-button class="buttonleft" @click="jumpBack()" >返回“填报准备”</el-button> -->
				<!-- <el-button class="buttonright" type="primary" @click="jumpTo()">进入“往年当量”</el-button> -->
				<!-- <el-button class="buttonright" type="primary" @click="jumpTo('/voluntarygroup')">进入“海选”方案</el-button> -->
			</div>
		</div>
		<div class="cardbox">
			<el-dialog :close-on-click-modal="false" title="填写大学导航卡号和真实高考分数" :showClose="false"
				:visible.sync="dialogVisible" width="50%">
				<el-form ref="cardform" :model="cardform" :rules="cardrules" label-width="200px">
					<el-form-item label="大学导航卡号" prop="cardnumber">
						<el-input v-model="cardform.cardnumber" placeholder="请输入卡号"></el-input>
					</el-form-item>
					<el-form-item label="卡号密码" prop="cardsecret">
						<el-input v-model="cardform.cardsecret" placeholder="请输入卡号"></el-input>
					</el-form-item>
					<el-form-item label="真实高考分数" prop="score">
						<el-input v-model="cardform.score" placeholder="请输入分数"></el-input>
					</el-form-item>
				</el-form>
				<span slot="footer" class="dialog-footer">
					<el-button @click="handleback">退出</el-button>
					<el-button type="primary" @click="handlesubit">确 定</el-button>
				</span>
			</el-dialog>
		</div>
		<div class="content" v-if="!display">
			<div class="emergency">
				<div style="font-family:Noto Sans SC;font-size:24px">系统维护中</div>
			</div>
		</div>
	</div>
</template>

<script>
	import timeCalculate from '../common/timeCalculate'
	export default {
		data() {
			return {
				form: {
					province: "",
					year: "",
					score: "",
					subject: "",
					batches: "",
					region: "",
				},
				// 高考年份
				Year: "",
				// 往年当年
				ReferenceYear: "",
				form1: {
					province: "",
				},
				year: "",
				getData: {},
				nextStep: "", //1为添加信息 else为修改信息
				allProvince: [],
				display: true,
				isActivation: '', //1为激活,0为未激活
				dialogVisible: false,
				cardform: {
					cardnumber: "",
					cardsecret: "",
					score: ""
				},
				cardrules: {
					cardnumber: [{
						required: true,
						message: "请输入卡号",
						trigger: "blur"
					}],
					cardsecret: [{
						required: true,
						message: "请输入卡号密码",
						trigger: "blur"
					}],
					score: [{
						required: true,
						message: "请输入分数",
						trigger: "blur"
					}]
				},
				cardstatus: false,
				data:"",
				res:"",
				provinceId:""
				
			}
		},
		methods: {
			jumpBack() {
				this.$router.push('/Preparationforfilling')
			},
			handlesubit() {
				this.$refs.cardform.validate((valid) => {
					if (valid) {
						this.$confirm('请确认所填写分数为当年真实高考分数，确定后将不能修改', '温馨提示', {
							confirmButtonText: '确定',
							cancelButtonText: '取消',
							type: 'warning'
						}).then(() => {
							// let fd = new FormData()
							// fd.append('cardNumber',this.cardform.cardnumber)
							// fd.append('cardPassword',this.cardform.cardsecret)
							let usename = JSON.parse(sessionStorage.username)
							this.$axios.post(
								`${this.baseURL}/sysAdmin/activeCard?cardNumber=${this.cardform.cardnumber}&cardPassword=${this.cardform.cardsecret}&username=${usename}`
								).then(res => {
									console.log(res)
									if(res.data.status == 500){
										this.$message({
											type: 'error',
											message: '卡号不存在或者密码不正确!',
											})
											// this.$router.push('/login')
										this.dialogVisible = true
										
									}
								else {
									this.$message({
									type: 'success',
									message: '填写成功!'
								})
								this.dialogVisible = false
								this.form.score = this.cardform.score
								this.cardstatus = true
								sessionStorage.setItem('isActivation', 1)
								}
							})
						}).catch(() => {
							return false
						});

					} else {
						return false
					}
				})
			},
			handleback() {
				sessionStorage.removeItem('username')
				sessionStorage.removeItem('active_user')
				sessionStorage.removeItem('isFilling')
				sessionStorage.removeItem('fromSelect')
				sessionStorage.removeItem('editInformation')
				sessionStorage.removeItem('token')
				sessionStorage.removeItem('preferredtable')
				sessionStorage.removeItem('tableSelection')
				sessionStorage.removeItem('limittable')
				sessionStorage.removeItem('limitselect')
				sessionStorage.removeItem('Optimalselect')
				sessionStorage.removeItem('firstform')
				sessionStorage.removeItem('form')
				sessionStorage.removeItem('finaltable')
				sessionStorage.removeItem('isActivation')
				sessionStorage.removeItem('isTest')
				// sessionStorage.removeItem('role')
				// this.adminFlag = false
				// console.log('l');
				this.$notify.success({
					title: "登出成功",
					message: "已退出登录"
				})
				// 向HOME组件传值
				this.$eventBus.$emit('adminFlag', false)
				this.$router.push('/login')
				return
			},
			formatDate(value) {
				let date = new Date(value);
				let y = date.getFullYear();
				let MM = date.getMonth() + 1;
				MM = MM < 10 ? "0" + MM : MM;
				let d = date.getDate();
				d = d < 10 ? "0" + d : d;
				let h = date.getHours();
				h = h < 10 ? "0" + h : h;
				let m = date.getMinutes();
				m = m < 10 ? "0" + m : m;
				let s = date.getSeconds();
				s = s < 10 ? "0" + s : s;
				return y + "-" + MM + "-" + d + " " + h + ":" + m + ":" + s;
			},
			jumpTo() {
				let date = new Date()
				//添加分数信息
				if (this.nextStep == 1) {
					console.log(this.form);
					this.$axios({
							method: 'post',
							url: `${this.baseURL}/scoreInfo/insertScoreInfo`,
							data: {
								batch: Number(this.form.batches),
								provinceId: Number(JSON.parse(sessionStorage.provinceId)),
								referenceYear: Number(this.form.region),
								score: Number(this.form.score),
								subject: Number(this.form.subject),
								username: JSON.parse(sessionStorage.username),
								year: this.Year,
							}
						})
						.then(async res => {
							console.log(res.data);
							if (res.data.status == 200) {
								let username = JSON.parse(sessionStorage.username)
								//同步请求
								await this.$axios.post(
										`${this.baseURL}/scoreInfo/getScoreInfoByUsername?username=${username}`)
									.then(res => {
										sessionStorage.setItem('form', JSON.stringify(res.data.data))
									})
								this.$router.push('/amount')
							} else {
								this.$notify.error({
									title: "失败",
									message: res.data.msg
								})
							}
						})
						.catch(err => {
							// console.log(err);
							this.$notify.error({
								title: "失败",
								message: "请检查写入的批次与成绩是否合理/本年分数线尚未公布"
							})
							return
						})
				}
				//修改分数信息
				else {
					console.log(this.form);
					this.$axios({
							method: 'post',
							url: `${this.baseURL}/scoreInfo/updateScoreInfo`,
							data: {
								batch: Number(this.form.batches),
								provinceId: Number(JSON.parse(sessionStorage.provinceId)),
								referenceYear: Number(this.form.region),
								score: Number(this.form.score),
								subject: Number(this.form.subject),
								username: JSON.parse(sessionStorage.username),
								year: this.Year,
								id: String(this.nextStep.id),
								// rank:12000
							}
						})
						.then(async res => {
							// console.log(res.data);

							if (res.data.status == 200) {
								let username = JSON.parse(sessionStorage.username)
								//同步请求 解决页面跳转后数据不更新
								await this.$axios.post(
										`${this.baseURL}/scoreInfo/getScoreInfoByUsername?username=${username}`)
									.then(res => {
										sessionStorage.setItem('form', JSON.stringify(res.data.data))
									})
								this.$router.push('/amount')

							}
						})
						.catch(err => {
							this.$notify.error({
								title: "失败",
								message: "请检查写入的批次与成绩是否合理/本年分数线尚未公布"
							})
							return
						})
				}
			}
		},
		mounted() {
			// 获取当前时间判断是否需要弹出卡填写框
			this.isActivation = JSON.parse(sessionStorage.isActivation)
			let time = JSON.parse(sessionStorage.time)
			let isTest = JSON.parse(sessionStorage.isTest)
			time = this.formatDate(time)
			console.log(time)
			// let provinceId = this.getData.provinceId
			let provinceId = JSON.parse(sessionStorage.provinceId)
			console.log(provinceId)
			// 判断是否是管理员测试号
			if (isTest) {
				this.ReferenceYear = time.substr(0, 4) - 1
				// 判断是否卡号被激活
			} else if (this.isActivation) {
				this.ReferenceYear = time.substr(0, 4) - 1
				this.cardstatus = true
			// 	// 判断时间是否到高考填写志愿的日子
			//
			// } else if ((time.substr(5, 6)).trim() <= "08-31" && (time.substr(5, 6)).trim() >= "06-01" ) {
			} else if ((time.substr(5, 6)).trim() <= "08-31" && (time.substr(5, 6)).trim() >= "06-22" && (provinceId==18 || provinceId==16 ) ) {
				// this.$router.push('/register')
				this.ReferenceYear = time.substr(0, 4) - 1
				this.dialogVisible = true
				// this.dialogVisible = false
			} else if((time.substr(5, 6)).trim() >= "08-31") {
				this.ReferenceYear = timeCalculate.timeCalculate()
			}else {
				this.ReferenceYear = timeCalculate.timeCalculate()-1
			}
			sessionStorage.setItem('finaltable', JSON.stringify(false))
			this.getData = JSON.parse(sessionStorage.form)
			this.Year = JSON.parse(sessionStorage.year) //获取高考年份
			let province = JSON.parse(sessionStorage.province)
			// let provinceId = this.getData.provinceId
			for (let i = 0; i <= province.length - 1; i++) {
				if (provinceId == province[i].id) {
					this.form1.province = province[i].provinceName
				}
			}
			this.nextStep = JSON.parse(sessionStorage.form) //判断为新增信息还是修改信息
			this.allProvince = JSON.parse(sessionStorage.province) //省份数据
			if (this.nextStep != 1) {
				let scoreData = this.nextStep
				this.form.province = Number(scoreData.provinceId)
				this.form.year = String(scoreData.year)
				this.form.score = String(scoreData.score)
				this.form.subject = String(scoreData.subject)
				this.form.batches = String(scoreData.batch)
				this.form.region = String(scoreData.referenceYear)
			}
			sessionStorage.setItem('Optimalselect', JSON.stringify(0))
			sessionStorage.setItem('status', JSON.stringify(0))
			if (sessionStorage.getItem('limittable')) {
				sessionStorage.removeItem('limittable')
			}
			if (sessionStorage.getItem('preferredtable')) {
				sessionStorage.removeItem('preferredtable')
			}
			if (sessionStorage.getItem('tableSelection')) {
				sessionStorage.removeItem('tableSelection')
			}
			// 监听回车按钮进入往年当量
			let _this = this
			document.onkeydown = function(e) {
				if (e.keyCode === 13) {
					_this.jumpTo()
				}
			}
		}
	}
</script>

<style scoped>
	.main {
		position: relative;
	}

	.content {
		width: 1440px;
		min-height: 804px;
		background-color: #fff;
		margin: 100px auto;
		/* position: relative; */
		margin-bottom: 24px;
		position: relative;
		z-index: 1;
	}

	.form>>>.el-input__inner {
		font-size: 30px !important;
	}

	.title {
		width: 100%;
		height: 210px;
		font-size: 40px;
		font-family: Noto Sans SC;
		color: #000000;
		/* margin: 0 auto; */
		font-weight: 700;
		/* margin-top: 80px; */
		letter-spacing: 2px;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.middle {
		display: flex;
		flex-direction: row;
	}

	.word {
		margin-top: 20px;
		font-size: 30px;
	}

	.blue {
		width: 8px;
		height: 40px;
		background: #33AAFF;
		margin-left: 68px;
	}

	.subtitle {
		/* width: 256px; */
		/* height: 32px; */
		font-size: 32px;
		font-family: Noto Sans SC;
		font-weight: 500;
		line-height: 43px;
		color: #000000;
		margin-left: 10px;
		letter-spacing: 1px;
	}

	.form {
		width: 1200px;
		min-height: 150px;
		/* background-color: aqua; */
		margin: 0 auto;
		margin-top: 25px;
		display: flex;
		flex-direction: row;
	}

	.form .left {
		flex: 1;
		/* background-color: black; */
	}

	.form .right {
		flex: 1;
		/* background-color: #fff; */
	}

	#selectform>>>.el-form-item__label {
		font-size: 30px;
		font-family: Noto Sans SC;
		color: #333333;
		line-height: 30px;
	}

	#selectform>>>.el-input__inner {
		border: 1px solid rgba(51, 170, 255, 1);
		border-radius: 8px;
		height: 100%;
		font-family: Noto Sans SC;
	}

	#selectform>>>.el-input {
		width: 325px;
		height: 45px;
	}

	.submit {
		width: 347px;
		height: 62px;
		/* background: #33AAFF; */
		opacity: 1;
		border-radius: 10px;
		font-size: 25px;
		font-family: Noto Sans SC;
		font-weight: 300;
		line-height: 41px;
		color: #FFFFFF;
		/* letter-spacing: 39px; */
	}

	.explain {
		font-size: 18px;
		font-family: Noto Sans SC;
		font-weight: 400;
		line-height: 25px;
		color: rgba(0, 0, 0, 0.45);
		/* width: 720px; */
		height: 18px;
		margin-left: 87px;
		margin-top: 18px;
		text-align: left;
	}

	.explain1 {
		/* display:flex; */
		font-family: Noto Sans SC;
		/* 	text-align: left;
		margin-top: 220px;
		margin-left: 90px; */
		float: right;
		font-size: 18px;
		width: 100%;

	}

	.explain2 {
		font-size: 20px;
		font-family: Noto Sans SC;
		font-weight: 400;
		line-height: 25px;
		color: rgba(0, 0, 0, 0.45);
		/* width: 720px; */
		height: 18px;
		margin-left: 10px;
		margin-top: 18px;
		text-align: left;
	}

	.input {
		width: 322.11px;
		float: left;
	}

	.cover {
		position: absolute;
		top: -210px;
		z-index: 0;
		/* width: 100%; */
		height: 276px;
		/* text-align: center; */
		left: 50%;
		margin-left: -960px;
		overflow: hidden;
	}

	.cover_c {
		position: relative;
		width: 100%;
	}

	.emergency {
		width: 100%;
		height: 100%;
		justify-content: center;
		align-items: center;
		display: flex;
	}

	.suoji {
		text-align: justify;
		text-justify: inter-ideograph;
		text-indent: 40px;
	}

	.select {
		width: 100%;
		position: fixed;
		left: 0;
		right: 0;
		bottom: 0;
		margin: auto;
		/* 	margin-top: 60px; */
		/* margin-bottom: 70px; */
	}

	.select .buttonleft {
		width: 347px;
		height: 62px;
		color: rgba(51, 170, 255, 1);
		float: left;
		font-size: 24px;
		font-family: Source Han Sans;
		font-weight: 100;
		line-height: 41px;
		border: 2px solid #33AAFF;
		border-radius: 10px;
	}

	.select .buttonright {
		width: 347px;
		height: 62px;
		/* float: left; */
		/* left:15%;
		bottom: 15%; */
		/* margin-left: 25%; */
		font-size: 24px;
		font-family: Source Han Sans;
		font-weight: 100;
		line-height: 41px;
		border-radius: 10px;
	}

	.cardbox>>>.el-form-item__label {
		font-size: 28px !important;
		line-height: 45px !important;
	}

	.cardbox>>>.el-input__inner {
		height: 50px;
		line-height: 50px;
	}

	.cardbox>>>.el-button--small {
		font-size: 24px;
	}

	.cardbox>>>.el-dialog__title {
		font-size: 30px;
		font-family: Source Han Sans;
	}

	.leftside {
		position: fixed;
		right: 5%;
		width: 85px;
		min-height: 48px;
		height: 200px;
		top: 50%;
		z-index: 100;
		box-shadow: 0 2px 12px 0 rgb(0 0 0 / 10%);
		border-radius: 40px;
		/* border: 10px solid black; */
		box-sizing: border-box;
		background: #fff;

	}

	.cndns-right-btn {
		border-radius: 40px;
		width: 100%;
		height: 50%;
		/* text-align: center; */
		display: block;
		margin-top: 10px;

		background-color: #fff;
	}

	i {
		font-size: 28px;
	}

	.text {
		margin-top: 3px;
		font-size: 20px;
		font-family: Source Han Sans;
		font-weight: bold;
	}

	/* .el-tooltip__popper{
	        background: rgba(0,0,0,0.65) !important;
	    } */
</style>
